﻿/***************************
* 1.天气
****************************/

/* 变量 */
var weather = "traffic/weather.html";

/* 天气首页  */
var contactsCallback_weather = myApp.onPageInit('weather', function (page) {

    // 天气
    Weather.Get(_type, function (date, weather_data, content, pm25, pm25Text) {

        if (weather_data && weather_data != null) {
            $("#weather_page .title").html(_type);
            // 当天
            $("#weather_page .today-temperature").text(weather_data[0].temperature);
            $("#weather_page .today-icon").css("background-image", "url(" + Weather.dayImg(weather_data[0].dayPictureUrl) + ")");
            // 近三天
            if (weather_data.length > 1) {
                var row = "";
                for (var i = 1; i < weather_data.length; i++) {
                    var col = "<div class='col-33 weather' style='border-right:1px solid #555;'>";
                    col += " <div class='date'>" + weather_data[i].date + "</div>";
                    col += " <div class='icon' style='background: url(" + Weather.dayImg(weather_data[i].dayPictureUrl) + ") center center no-repeat; background-size: 60%;'></div>";
                    col += " <div class='temperature'>" + weather_data[i].temperature + "</div>";
                    col += " <div class='quality'>" + weather_data[i].wind + "</div>";
                    col += "</div>";
                    row += col;
                }
                if (row != "") {
                    $("#weather_page .page-content .three-day .row").html(row);
                }
            }
        }
    })

});

/* 初始化  */
function initData() {
    var href = window.location.href;
    if (href.indexOf(weather) > -1) {
        contactsCallback_weather.trigger();
    }
}

initData();